//
//  SettingViewController.m
//  citzenWorkStation
//
//  Created by yang qing on 2018/3/2.
//  Copyright © 2018年 yang qing. All rights reserved.
//

#import "SettingViewController.h"
#import "UIColor+Hex.h"
#import "ForgetPswViewController.h"
#import "AboutViewController.h"
#import "DataSaveUtils.h"
@interface SettingViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (strong,nonatomic) NSMutableArray *dataArray;
@end

@implementation SettingViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self initView];
    self.dataArray = [[NSMutableArray alloc]init];
    [self.dataArray addObject:@"修改密码"];
    [self.dataArray addObject:@"关于"];
}
- (void)initView{
    [self initNav];
    self.view.backgroundColor = [UIColor colorWithHexString:@"ededed"];
    
    UITableView *tableView =[[UITableView alloc]initWithFrame:CGRectMake(0, 64,[[UIScreen mainScreen]bounds].size.width, [[UIScreen mainScreen]bounds].size.height-66-64) style:UITableViewStylePlain];
    tableView.delegate = self;
    tableView.dataSource = self;
//    tableView.separatorInset = UIEdgeInsetsZero;//设置分割线宽全屏
    tableView.backgroundColor = [UIColor clearColor];
    [self.view addSubview:tableView];
    //分割线颜色
    tableView.separatorColor = [UIColor colorWithHexString:@"ededed"];
//    行高
    tableView.rowHeight = 46;
    
    UIButton *btnQuit = [UIButton buttonWithType:UIButtonTypeCustom];
    btnQuit.frame = CGRectMake(20, [[UIScreen mainScreen]bounds].size.height-66,[[UIScreen mainScreen]bounds].size.width-40, 46);
    [btnQuit setTitle:@"退出登录" forState:UIControlStateNormal];
    [btnQuit setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    btnQuit.backgroundColor = [UIColor colorWithHexString:ThemeColor];
    [btnQuit addTarget:self action:@selector(quickClick) forControlEvents:UIControlEventTouchUpInside];
    
    [self.view addSubview:btnQuit];
    
}
- (void)quickClick{
//    [self showToast:@"退出"];
    [DataSaveUtils clearUserInfo];
    [self.navigationController dismissViewControllerAnimated:YES completion:nil];
    [self showToast:@"已退出"];
    
}

#pragma marker - UITableViewDelegate

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    if(cell == nil){
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cell"];
        
        cell.backgroundColor = [UIColor whiteColor];
    }
    cell.textLabel.text = self.dataArray[indexPath.row];
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.textLabel.textColor = [UIColor blackColor];
    return cell;
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.dataArray.count;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
   
    if(indexPath.row == 0){
        ForgetPswViewController *forgetPswVc = [[ForgetPswViewController alloc]init];
        forgetPswVc.titleName = @"修改密码";
        [self.navigationController pushViewController:forgetPswVc animated:YES];
    }else if(indexPath.row == 1){
        AboutViewController *aboutVc = [[AboutViewController alloc]init];
        [self.navigationController pushViewController:aboutVc animated:YES];
    }
    

    
}

- (void)initNav{
    self.navigationController.navigationBar.barTintColor =
    [UIColor colorWithHexString:ThemeColor];
    //设置导航栏标题文字和文字大小
    [self setNavtitle:@"设置"];
    //设置两侧按钮
    [self setNavLeftImg:@"nav_back"];
}

- (void)setNavtitle:(NSString *)title{
    self.navigationItem.title = title;
    [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor],NSFontAttributeName:[UIFont systemFontOfSize:20]}];
}
- (void)setNavLeftImg:(NSString *)name{
    UIButton *menuButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [menuButton setFrame:CGRectMake(-20.0, 0.0, 44.0, 44.0)];
    [menuButton addTarget:self action:@selector(backClick) forControlEvents:UIControlEventTouchUpInside];
    [menuButton setImage:[UIImage imageNamed:name] forState:UIControlStateNormal];
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, 44.0, 44.0)];
    [view addSubview:menuButton];
    UIBarButtonItem *leftItem = [[UIBarButtonItem alloc] initWithCustomView:view];
    self.navigationItem.leftBarButtonItem = leftItem;
}

- (void)backClick{
    [self dismissViewControllerAnimated:YES completion:nil];
}

@end
